<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<c:set var="ctxPath" value="${pageContext.request.contextPath}"/>

<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<link rel="stylesheet" href="${ctxPath}/static/layui/css/layui.css"/>
	<title>申请报销</title>
	<script src="${ctxPath}/static/layui/layui.js"></script>
	<script src="${ctxPath}/static/js/jquery-3.6.1.min.js"></script>
</head>
<body>
<fieldset class="layui-elem-field layui-field-title"
		  style="margin-top: 20px;">
	<legend>申请请假页</legend>
</fieldset>
}
<script src="${ctxPath}/static/js/jquery-3.6.1.min.js"></script>
<script>
function submitLeave(){
	$.ajax(
		{
			url:'${ctxPath}/Leave/submitLeave',
			type:'post',
			data:{
				initiator:$('#initiator').val(),
				startDate:$('#startDate').val(),
				endDate:$('#endDate').val(),
				leaveType:$('#leaveType').val(),
				reason:$('#reason').val()
			},
			dataType:"json",
			success:function( json ){
				console.log("json"+ json );
				let ret = json['result'];
				let cause = json['cause'];
				if( ret==="success" ){
					alert('申请请假成功。');
					//{ps}查看我发起的任务。
					window.location = "${ctxPath}/Leave/myInitiate";
				}else{
					alert('申请请假失败, 原因:'+ cause);
				}
			}
		}
	);
}
</script>

<form id="frmLeave" class="layui-form">
	<!--  发起人ID:initiator -->
	<input id="initiator" type="hidden" value="${user.id}"/><br/>
	
<%--	<label>开始时间:</label>--%>
<%--	<input id="startDate" type="text" /><br/>--%>

	<div class="layui-form-item" style="margin-left:20px;">
		<div class="layui-inline">
			<label class="layui-form-label">开始时间:</label>
			<div class="layui-input-block" style="width:190px;">
				<input type="text" id="startDate"
					   placeholder="请输入开始时间" class="layui-input">
			</div>
		</div>
	</div>


<%--	<label>结束时间:</label>--%>
<%--	<input id="endDate" type="text" /><br/>--%>


	<div class="layui-form-item" style="margin-left:20px;">
		<div class="layui-inline">
			<label class="layui-form-label">结束时间:</label>
			<div class="layui-input-block" style="width:190px;">
				<input type="text" id="endDate"
					    placeholder="请输入结束时间" class="layui-input">
			</div>
		</div>
	</div>


	
<%--	<label>请假类型:</label> --%>
<%--	<select id="leaveType">--%>
<%--		<option value="事假">事假</option>--%>
<%--		<option value="年假">年假</option>--%>
<%--		<option value="病假">病假</option>--%>
<%--		<option value="婚假">婚假</option>--%>
<%--		<option value="产假">产假</option>--%>
<%--		<option value="陪产假">陪产假</option>--%>
<%--	</select>--%>

	<div class="layui-form-item" style="margin-left:20px;">
		<div class="layui-inline">
			<label class="layui-form-label">请假类型:</label>
			<div class="layui-input-block" style="width:190px;">
				<select class="layui-select" id="leaveType">
					<option value="事假">事假</option>
					<option value="年假">年假</option>
					<option value="病假">病假</option>
					<option value="婚假">婚假</option>
					<option value="产假">产假</option>
					<option value="陪产假">陪产假</option>
				</select>
			</div>
		</div>
	</div><br/>
	
<%--	<label>请假原因:</label> --%>
<%--	<textarea id="reason" cols="35" rows="5">--%>
<%--	</textarea>--%>

	<div class="layui-form-item" style="margin-left:20px;">
		<div class="layui-inline">
			<label class="layui-form-label">请假原因:</label>
			<div class="layui-input-block" style="width:190px;">
				<textarea id="reason" class="layui-textarea"></textarea>
			</div>
		</div>
	</div>

	<br/>
	
<%--	<input type="button" value="提交请假" --%>
<%--		onclick="submitLeave();"/>--%>
	<div class="layui-form-item" style="margin-left:20px;">
		<div class="layui-inline">
			<label class="layui-form-label">请假原因:</label>
			<div class="layui-input-block" style="width:190px;">
				<button type="button" class="layui-btn"
						onclick="submitLeave();">提交请假
				</button>
			</div>
		</div>
	</div><br/><br/>
</form>
</div>
</body>
</html>